/*
 * @Date: 2022-02-14 11:24:10
 * @LastEditors: 春贰
 * @gitee: https://gitee.com/chun22222222
 * @github: https://github.com/chun222
 * @Desc:
 * @LastEditTime: 2022-06-02 15:08:18
 * @FilePath: \server\system\controller\sys\pdf\pdf.go
 */
package pdf

import (
	"fmt"

	"go2admin_pure/system/core/request"
	"go2admin_pure/system/core/response"
	pdfutil "go2admin_pure/system/util/pdf"
	"github.com/gin-gonic/gin"
)

func GenPdf(c *gin.Context) {
	var r pdfutil.PdfReuest
	err, msg := request.Binding(&r, c)
	if err != nil {
		response.FailWithMessage(msg, c)
		return
	}

	if err, ret := pdfutil.Instance().CreatePdf(&r); err != nil {
		response.FailWithMessage(err.Error(), c)
	} else {
		c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", ret.Name))
		c.File(ret.Fullpath)
		//response.OkWithData(ret, c)
	}

}
